<template>
    <div class="service-list">

        <div class="cateTab">
            <div class="cateTab-list">
                <div class="cateTab-type-title">服务商类别：</div>
                <div class="cateTab-type-item" :class="{ 'cateTab-type-item-active': selectType == '' }"
                    @click="clickType('')">
                    全部
                </div>
                <div class="cateTab-type-item" :class="{ 'cateTab-type-item-active': selectType == '1' }"
                    @click="clickType('1')">
                    企业服务商
                </div>
                <!-- <div
                    class="cateTab-type-item"
                    :class="{ 'cateTab-type-item-active': selectType == '2' }"
                    @click="clickType('2')"
                >
                    金牌服务商
                </div>
                <div
                    class="cateTab-type-item"
                    :class="{ 'cateTab-type-item-active': selectType == '3' }"
                    @click="clickType('3')"
                >
                    银牌服务商
                </div>
                <div
                    class="cateTab-type-item"
                    :class="{ 'cateTab-type-item-active': selectType == '4' }"
                    @click="clickType('4')"
                >
                    铜牌服务商
                </div> -->
                <div class="cateTab-type-item" :class="{ 'cateTab-type-item-active': selectType == '6' }"
                    @click="clickType('6')">
                    个人服务商
                </div>
            </div>
            <div class="cateTab-list" style="margin-bottom: 0;">
                <div class="cateTab-type-title" style="margin-right: 0">
                    擅长服务：
                </div>
                <div class="cateTab-type-item2" :class="{
                    'cateTab-type-item-active2': allCateCurrent == null,
                }" @click="selectCate(null)">
                    全部
                </div>
                <div v-for="(item, index) in allCate" :key="index" class="cateTab-type-item2" :class="{
                    'cateTab-type-item-active2': allCateCurrent == index,
                }" @click="selectCate(index)">
                    {{ item.name }}
                    <i :class="allCateCurrent == index && isGL ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
                </div>
            </div>
            <div class="cateTab-list">
                <div class="cateTab-type-title" style="margin-right: 0"></div>
                <div class="cateTab-type-3 cateTab-list-transition"
                    :style="{ height: twoCate.length > 0 && isGL ? allCateCurrent == 2 ? '79px' : '53px' : 0, padding: twoCate.length > 0 && isGL ? '10px 0 17px' : 0 }">
                    <span v-for="(item, index) in twoCate" :key="index" :class="{ active: selectCateTwo == item.id }"
                        @click="clickCateTwo(item)">{{ item.name }}</span>
                </div>
            </div>
            <div class="cateTab-list">
                <div class="cateTab-type-title">服务商所在地：</div>
                <div v-for="(item, index) in hotCity" :key="index" class="cateTab-type-item" :class="{
                    'cateTab-type-item-active': citySelect == item.id,
                }" @click="cityClick(item)">
                    {{ item.name }}
                </div>

                <el-popover placement="bottom" width="244" trigger="click">
                    <el-cascader ref="citySelect" class="cate-tab-select" v-model="address" :options="region" :props="{
                        value: 'id',
                        label: 'name',
                        children: 'children',
                    }" clearable filterable @change="cityChange"></el-cascader>
                    <div slot="reference" class="cateTab-type-item" :class="{
                        'cateTab-type-item-active': selectAddress != '更多',
                    }">
                        {{ selectAddress }}
                        <i class="el-icon-arrow-down"></i>
                    </div>
                </el-popover>
            </div>
        </div>

        <div class="con flex-sb">
            <div class="left">
                <div v-for="(item, index) in dataList" :key="index" class="service-item">
                    <div class="service-info">
                        <!-- <img class="service-info-log" :src="item.logo" alt="" /> -->
                        <el-image class="service-info-log" :src="item.logo" :alt="item.name" fit="cover"
                            @click="goDetail(item.id)">
                        </el-image>
                        <div class="service-info-text">
                            <div class="title" @click="goDetail(item.id)">
                                {{ item.name }}
                            </div>
                            <div class="tags">
                                <img :src="getServiceType(item.type)" class="service-type" alt="" />
                                <div v-if="item.cash_deposit != '0'">保证金{{ item.cash_deposit }}</div>
                            </div>
                        </div>
                    </div>
                    <div class="service-info-skill">
                        <span class="service-info-skill-tag" style="width: 130px;">
                            <i class="el-icon-location"></i>{{ item.city }}
                        </span>
                        <span class="service-info-skill-tag">
                            <i class="el-icon-s-claim"></i>累计服务：{{ item.sales }}
                        </span>
                    </div>
                    <div class="service-info-line">
                        Ta的商品
                    </div>
                    <div class="service-pic-list">
                        <div v-for="pic in item.services_shop.slice(0, 2)" :key="pic.id" class="service-pic-item"
                            @click="goServiceShopsDetail(pic)">
                            <span style=" padding-left: 6px;color: #FA5151;">￥{{ pic.price }}</span>
                            <span class="name">{{ pic.name }}</span>
                        </div>
                        <div v-if="item.services_shop.length == 0" class="service-pic-item">
                            暂无商品
                        </div>
                    </div>
                    <div class="zx" @click="goDetail(item.id)">
                        店铺>
                    </div>
                </div>

                <div v-if="dataList.length == 0" style="width: 900px;">
                    <el-empty description="暂无数据"></el-empty>
                </div>
            </div>
            <div class="right">
                <div class="title">为什么选择我们</div>
                <div class="youshi-list">
                    <div class="youshi-item">
                        <img src="~/assets/images/service/xzwm1.png" alt="" />
                        <div class="youshi-info">
                            服务专业
                            <div>服务商实名认证，精准入驻平台</div>
                        </div>
                    </div>
                    <div class="youshi-item">
                        <img src="~/assets/images/service/xzwm2.png" alt="" />
                        <div class="youshi-info">
                            价格透明
                            <div>收费依规依据，资金全面监管</div>
                        </div>
                    </div>
                    <div class="youshi-item">
                        <img src="~/assets/images/service/xzwm3.png" alt="" />
                        <div class="youshi-info">
                            流程可靠
                            <div>服务进度实时可视，流程标准可控</div>
                        </div>
                    </div>
                    <div class="youshi-item">
                        <img src="~/assets/images/service/xzwm4.png" alt="" />
                        <div class="youshi-info">
                            口碑真实
                            <div>服务评价真实有效，可参考可信赖</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div v-if="dataList.length > 0" class="page" style="width: 900px;margin-left: calc(50% - 600px);">
            <el-pagination background layout="prev, pager, next" :total="total" :page-size="limit"
                :current-page.sync="page" @current-change="changePage">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { getcate_new, getServiceList } from "@/assets/api/service";
import { goTopSmooth } from "@/assets/utils/utils";
import region from "@/assets/json/region-just-city.json";

import { mapState } from "vuex";

import serviceType5 from "@/assets/images/service/index/serviceType1.png";
import serviceType6 from "@/assets/images/service/index/serviceType6.png";

export default {
    head() {
        return {
            title: "服务商列表-【小竹财税平台】",
            meta: [
                {
                    hid: "keywords",
                    name: "keywords",
                    content: "小竹财税,服务商,服务商列表",
                },
            ],
        };
    },
    layout: "serverHome",
    data() {
        return {
            allCate: [],
            allCateCurrent: null,
            twoCate: [],
            dataList: [],

            getServiceType: function (type) {
                switch (type) {
                    case 1:
                        return serviceType5;
                    case 2:
                        return serviceType5;
                    case 3:
                        return serviceType5;
                    case 4:
                        return serviceType5;
                    case 5:
                        return serviceType5;
                    case 6:
                        return serviceType6;
                    default:
                        break;
                }
            },

            // 热门城市
            hotCity: [
                {
                    name: "全国",
                    id: null,
                },
                {
                    name: "合肥",
                    id: "340100",
                },
            ],

            region: [],
            address: "",
            selectAddress: "更多",
            citySelect: null,
            selectType: "",
            selectCateTwo: "",
            sort: 0,

            page: 1,
            limit: 10,
            total: 0,

            keyword: '',
            isGL: true

        };
    },
    beforeDestroy() { },
    beforeMount() { },
    mounted() {
        goTopSmooth();
        this.init();
    },
    computed: {
        ...mapState("common", {
            userInfo: (state) => state.userInfo,
        }),
    },
    watch: {
        '$route.query.keyword'(n, o) {
            this.keyword = n
            this.getServiceList();
        }
    },
    methods: {
        init() {
            let regionList = region;
            for (let items of regionList) {
                for (let item of items.children) {
                    delete item.children;
                }
            }
            this.region = regionList;
            this.getcate_new();
            this.getServiceList();
        },

        async getcate_new() {
            const res = await getcate_new({});
            if (res.code == 1) {
                this.allCate = res.data;
            }
        },

        // 获取列表
        async getServiceList(goTop = false) {
            let params = {
                sort: this.sort,
                page: this.page,
                pageSize: this.limit,
                keyword: this.$route.query.keyword
            };
            if (this.selectAddress != "更多") {
                params.city_code = this.address[1];
            } else if (this.citySelect) {
                params.city_code = this.citySelect;
            }
            if (this.selectType) {
                params.type = this.selectType;
            }
            if (this.allCateCurrent != null) {
                params.one_cate_id = this.allCate[this.allCateCurrent].id;
            }
            if (this.selectCateTwo) {
                params.two_cate_id = this.selectCateTwo;
            }
            const res = await getServiceList(params);
            if (res.code == 1) {
                this.dataList = res.data.list;
                this.total = res.data.listcount;
                // 回到顶部
                if (goTop) goTopSmooth();
            }
        },

        // 修改分页
        changePage(page) {
            // console.log(page)
            this.page = page;
            this.getServiceList(true);
        },

        // 选择一级分类
        selectCate(index) {
            if (index != null) {
                this.twoCate = this.allCate[index].two;
                this.getServiceList();
                if (this.allCateCurrent == index) this.isGL = !this.isGL
                else this.isGL = true
            } else {
                this.twoCate = [];
                this.selectCateTwo = "";
                this.getServiceList();
            }
            this.allCateCurrent = index;
        },

        // 选择二级分类
        clickCateTwo(item) {
            this.page = 1;
            if (this.selectCateTwo == item.id) return;
            this.selectCateTwo = item.id;
            this.getServiceList();
        },

        cityChange(citys) {
            let label = "";
            for (let items of this.region) {
                if (items.id == citys[0]) {
                    for (let item of items.children) {
                        if (item.id == citys[1]) {
                            label = item.name;
                        }
                    }
                }
            }
            if (!label || this.selectAddress == label) return;
            this.page = 1;
            this.citySelect = "";
            this.selectAddress = label;
            this.getServiceList();
        },

        cityClick(item) {
            if (this.citySelect == item.id) return;
            this.page = 1;
            this.selectAddress = "更多";
            this.address = ''
            this.citySelect = item.id;
            this.getServiceList();
        },

        // 选择服务商类型
        clickType(type) {
            if (this.selectType == type) return;
            this.page = 1;
            this.selectType = type;
            this.getServiceList();
        },

        clickTab(index) {
            if (this.sort == index) return;
            this.page = 1;
            this.sort = index;
            this.getServiceList();
        },

        goDetail(id) {
            window.open(`/service/servicedetail?id=${id}`, '_blank');
        },

        goServiceShopsDetail(item) {
            this.$router.push({
                path: "/service/serviceshopsdetail",
                query: {
                    id: item.id,
                },
            });
        },

        goChat(item) {
            if (!this.userInfo) {
                this.$confirm("该功能需要登录后使用", "提示", {
                    confirmButtonText: "去登录",
                    cancelButtonText: "再看看",
                })
                    .then(() => {
                        this.$router.push({
                            path: "/login",
                            query: {
                                url:
                                    window.location.pathname +
                                    window.location.search,
                            },
                        });
                    })
                    .catch(() => { });
                return;
            }
            localStorage.setItem("to_zim_userid", item.user_id);
            this.$router.push({
                path: "/service/servicechat",
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.service-list {
    position: relative;
    padding-top: 50px;
    overflow: hidden;
}

.service-bj {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
}

.cateTab {
    position: relative;
    z-index: 1;
    width: 1200px;
    margin: 20px auto;
    margin-top: 0;
    background-color: #fff;
    padding: 14px 15px;
    box-sizing: border-box;
}

.cateTab-list {
    display: flex;
    align-items: center;
    margin-bottom: 10px;

    .cateTab-type-title {
        width: 100px;
        min-width: 100px;
        font-size: 14px;
        color: #020C17;
        text-align: right;
        // margin-right: 14px;
    }

    .cateTab-type-item {
        // height: 28px;
        // line-height: 28px;
        // padding: 0 10px;
        // border-radius: 3px;
        font-size: 14px;
        color: #020C17;
        text-align: center;
        // margin-right: 28px;
        padding: 0 14px;
        cursor: pointer;
        height: 28px;
        line-height: 28px;

        &:hover {
            color: #1B8DFF;
            opacity: 0.85;
        }
    }

    .cateTab-type-item-active {
        background: rgba(27, 141, 255, 0.12);
        color: #1B8DFF;
    }

    .cateTab-type-item2 {
        height: 28px;
        line-height: 28px;
        padding: 0 14px;
        font-size: 14px;
        color: #020C17;
        text-align: center;
        display: flex;
        align-items: center;
        cursor: pointer;

        &:hover {
            opacity: 0.85;
            color: #1B8DFF;
        }

        span {
            white-space: nowrap;
            /* 禁止换行 */
            overflow: hidden;
            /* 隐藏溢出内容 */
            text-overflow: ellipsis;
            /* 显示省略号 */
            width: 68px;
            display: block;
        }

        i {
            font-size: 14px;
            padding-left: 2px;
        }
    }

    .cateTab-type-item-active2 {
        background: rgba(27, 141, 255, 0.12);
        // background: burlywood;
        color: #1B8DFF;
    }

    // .cateTab-type-3 {
    //     background: #f9f9f9;
    //     // background: burlywood;
    //     padding: 7px 20px;
    //     // display: flex;
    //     // align-items: center;
    //     // flex-wrap: wrap;
    //     width: 100%;

    //     div {
    //         font-size: 14px;
    //         color: #666666;
    //         cursor: pointer;
    //     }

    //     .cateTab-3-list {
    //         padding: 5px 0;
    //         display: flex;

    //         .cateTab-3-list-name {
    //             min-width: 120px;
    //             line-height: 22px;
    //         }

    //         .cateTab-3-list-third {
    //             display: flex;
    //             flex-wrap: wrap;

    //             div {
    //                 margin-right: 10px;
    //                 line-height: 22px;
    //             }
    //         }
    //     }

    //     .active {
    //         color: #ff6900;
    //     }
    // }

    .cateTab-type-3 {
        background: rgba(27, 141, 255, 0.12);
        padding: 10px 0 17px;
        padding-left: 20px !important;
        padding-right: 20px !important;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        width: 100%;

        span {
            font-size: 14px;
            color: #666666;
            margin-right: 34px;
            display: block;
            cursor: pointer;
            padding-top: 7px;

            &:hover {
                color: #1B8DFF;
            }
        }

        .active {
            color: #1B8DFF;
        }
    }
}

.con {
    width: 1200px;
    margin: 0 auto;
    margin-bottom: 30px;
    align-items: flex-start;
    position: relative;
    z-index: 1;

    .left {
        width: 900px;
        display: grid;
        grid-template-columns: 440px 440px;
        gap: 20px;
    }

    .right {
        width: 280px;
        background: #FFFFFF;
        padding: 28px 25px;
        padding-right: 0;

        .title {
            text-align: center;
            font-size: 20px;
            color: #333333;
            padding-top: 28px;
            padding-right: 25px;
        }
    }
}

.cateTab-list-transition {
    transition: all 0.3s;
    overflow: hidden;
}

.service-item {
    height: 220px;
    padding: 10px;
    position: relative;
    background-color: #FFFFFF;
    border-radius: 10px;

    &:hover {
        box-shadow: 0px 0px 12px 0px rgba(5, 50, 94, 0.12);
    }

    .service-info {
        display: flex;
        width: 420px;
        background: #F7F8FA;
        border-radius: 10px 10px 0 0;
        padding: 10px;

        .service-info-log {
            min-width: 60px;
            width: 60px;
            height: 60px;
            margin-right: 6px;
            border-radius: 60px;
            cursor: pointer;
        }

        .service-info-text {

            .title {
                display: flex;
                align-items: center;
                font-size: 18px;
                font-weight: 500;
                color: #333333;
                cursor: pointer;

                .service-type {
                    display: block;
                    width: 96px !important;
                    height: 24px !important;
                    border-radius: 0 !important;
                    margin-left: 12px;
                }
            }

            .tags {
                padding-top: 6px;
                display: flex;
                align-items: center;

                img {
                    height: 27px;
                    width: auto;
                    margin-right: 20px;
                }

                div {
                    height: 20px;
                    padding: 0 12px;
                    line-height: 20px;
                    text-align: center;
                    background: #FF6900;
                    border-radius: 3px;
                    font-size: 12px;
                    color: #FFFFFF;
                }
            }
        }


    }

    .service-info-skill {
        border-radius: 0 0 10px 10px;
        background: #F7F8FA;
        display: flex;
        align-items: center;
        font-size: 14px;
        color: #999999;
        flex-wrap: wrap;
        margin-bottom: 15px;
        padding: 3px 10px 10px;

        .service-info-skill-tag {
            display: block;
            font-size: 14px;
            color: #000B1A;

            i {
                color: #1C87F3;
                padding-right: 4px;
                font-size: 16px;
            }
        }

        .service-info-skill-tag2 {
            display: block;
            margin-bottom: 6px;
        }

        .tag {
            display: block;
            min-width: 69px;
            height: 24px;
            line-height: 24px;
            text-align: center;
            // background: #F4F4F4;
            border-radius: 2px;
            margin-right: 11px;
            margin-bottom: 6px;
        }
    }

    .service-info-line {
        font-size: 14px;
        color: #000B1A;
        display: flex;
        align-items: center;
        white-space: nowrap;
        justify-content: space-between;

        &::after {
            content: '';
            width: 348px;
            height: 1px;
            display: block;
            background-color: #9E9E9E;
        }
    }

    .service-pic-list {
        margin-top: 8px;
        font-weight: 600;
        font-size: 14px;
        color: #000B1A;

        .service-pic-item {
            cursor: pointer;
            padding-bottom: 4px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;

            &:hover .name {
                text-decoration: underline;
            }
        }

    }

    .zx {
        font-size: 14px;
        color: #FFFFFF;
        width: 72px;
        height: 28px;
        line-height: 28px;
        background: #1C87F3;
        border-radius: 6px;
        text-align: center;
        position: absolute;
        right: 20px;
        top: 46px;
        cursor: pointer;

        &:hover {
            opacity: 0.85;
        }
    }
}

.page {
    text-align: center;
    padding-bottom: 30px;
    width: 900px;
}

.youshi-list {
    .youshi-item {
        display: flex;
        align-items: center;
        padding-top: 20px;

        img {
            width: 40px;
            height: 40px;
            object-fit: cover;
        }

        .youshi-info {
            font-size: 16px;
            color: #333333;
            margin-left: 10px;

            div {
                font-size: 12px;
                color: #999999;
            }
        }
    }
}
</style>./servicelist.vue